export const schema = {
    type: "page",
    title: "项目信息编辑",
    body: [
        {
            type: "nav",
            stacked: false,
            links: [
                {
                    label: "查看",
                    to: "/project/view/${id}"
                },
                {
                    label: "编辑",
                    visibleOn: 'acl.can("project:create")',
                    to: "/project/edit/${id}"
                },
                {
                    label: "签到码",
                    to: "/project/checkin/${id}",
                    // acl: "project:create",
                    visibleOn: 'acl.can("project:create")',
                },
                {
                    label: "录用管理",
                    to: "/project/hire/${id}",
                    visibleOn: 'acl.can("project:create")',
                    // acl: "project:create"
                },
                {
                    label: "志愿时长",
                    to: "/project/work/${id}",
                    visibleOn: 'acl.can("project:create")',
                    // acl: "project:create"
                }
            ]
        },

        {
            type: "wrapper",
            className: "b-l b-b b-r bg-white no-padder",
            body: {
                type: "crud",
                api: "/api/project/${params.id}/checkin?page=${page}",
                panelClassName: "no-border no-shadow bg-white",
                toolbarInline: true,
                toolbar: {
                    label: "新建签到码",
                    type: "button",
                    size: "sm",
                    actionType: "dialog",
                    icon: "pull-left btn-info",
                    className: "btn btn-info",
                    dialog: {
                        title: "新建签到码",
                        size: "lg",
                        body: {
                            type: "form",
                            api: "post:/api/project/${params.id}/checkin",
                            initApi: "get:/api/project/${params.id}/initCheckin",
                            controls: [
                                [
                                    {
                                        label: "签到时间",
                                        name: "begin",
                                        type: "datetime",
                                        inputFormat: "YYYY-MM-DD HH:mm",
                                        required: true
                                    },
                                    {
                                        label: "到",
                                        labelClassName: "w-1x m-l-n",
                                        name: "end",
                                        type: "datetime",
                                        inputFormat: "YYYY-MM-DD HH:mm",
                                        required: true
                                    }
                                ],

                                {
                                    type: "map",
                                    label: "签到地点",
                                    name: "address",
                                    required: true
                                },

                                [
                                    {
                                        type: "number",
                                        label: "签到有效范围",
                                        name: "distance",
                                        width: 80,
                                        min: 0.1,
                                        step: 0.1,
                                        validations: `minimum:0.1`,
                                        required: true
                                    },
                                    {
                                        type: 'plain',
                                        label: false,
                                        value: '单位 KM，请输入大于 0.1的值'
                                    }
                                ],

                                [
                                    {
                                        type: "number",
                                        label: "计入时长",
                                        width: 80,
                                        step: 0.5,
                                        min: 0,
                                        max: 8,
                                        validations: `minimum:0,maximum:8`,
                                        name: "reward_time",
                                        required: true
                                    },
                                    {
                                        label: false,
                                        type: 'plain',
                                        value: '单位小时 请输入 0 - 8 之间'
                                    }
                                ]
                            ]
                        }
                    }
                },
                columns: [
                    {
                        name: "name",
                        label: "签到日期",
                        type: "tpl",
                        tpl: '${begin|date} - ${end|date}'
                    },
                    {
                        label: "签到计入时长",
                        name: 'reward_time'
                    },
                    {
                        label: "签到密令",
                        name: 'code'
                    },

                    {
                        label: "签到码",
                        type: "operation",
                        width: 180,
                        buttons: [
                            {
                                type: "button",
                                size: 'xs',
                                label: '查看',
                                actionType: 'dialog',
                                dialog: {
                                    disabled: true,
                                    title: "查看签到码",
                                    size: 'sm',
                                    body: `
                                        <div class="text-center">
                                            <img src="/qrcode?size=250&data=<%= encodeURIComponent(data.project_id) %>" />
                                        </div>
                                    `
                                }
                            },
                            {
                                type: "button",
                                size: "xs",
                                label: "删除",
                                level: "danger",
                                actionType: 'ajax',
                                api: 'delete:/api/project/${project_id}/checkin/${id}',
                                confirmText: '确定要删除？'
                            }
                        ]
                    }
                ]
            }
        }
    ]
};
